<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>我的学员</title>
<link rel="stylesheet" type="text/css"
	href="/bootstrap/bootstrap.4.1.0.css">
<script src="/bootstrap/jquery.3.2.1.min.js"></script>
<script src="/bootstrap/popper.12.5.min.js"></script>
<script src="/bootstrap/bootstrap.4.1.0.min.js"></script>
<script src="/layui/layer/layer.js"></script>
<script src="/vue/Vue.js"></script>
<script src="/vue/axios.js"></script>
<style type="text/css">
.active {
	background-color: blue;
}
</style>
<script type="text/javascript">
	$(function(){
		$("#header").load("/zlz/header.html");
	})
</script>
</head>
<body>
	<div id="header" >
	</div>
	<div id="all" class="container">
		<div v-if="students!=null">
				<table class="table table-striped table-hover text-center">
				<thead>
					<tr>
						<th>序号</th>
						<th>昵称</th>						
						<th>头像</th>
						<th>微信</th>
						<th>qq</th>
						<th>电话</th>
						<th>描述</th>
						<th>查看</th>
					</tr>
				</thead>
				<tbody>
					<tr v-for="(student,index) in students" :key="index">
						<td>{{index+1}}</td>
						<td>{{student.nickname}}</td>
						<td>{{student.avarta}}</td>
						<td>{{student.wechat}}</td>
						<td>{{student.qq}}</td>
						<td>{{student.phone}}</td>
						<td>{{student.description}}</td>
						<td><button	class="btn btn-outline-primary" @click="detail(student.id)">查看详情</button>
					</tr>
				</tbody>
			</table>
			
			<div class="row">
				<div class="offset-md-5">
					<ul class="pagination">
						<li class="page-item"><a class="page-link" href="#"
							@click.prevent="prePage"> <</a></li>
						<li class="page-item" v-for="(item, index) in pageNum"><a
							class="page-link" href="#" v-on:click.prevent="getFriends(item)"
							:class="{active: currentPage==index+1}">{{ index+1 }}</a></li>
						<li class="page-item"><a class="page-link" href="#"
							v-on:click.prevent="nextPage">></a></li>
					</ul>
				</div>
			</div>
		</div>
		<div v-else class="row">
			<p class="offset-md-5">您还没有好友</p>
		</div>
	</div>
</body>
<script type="text/javascript">
	new Vue({
		el:"#all",
		data:{
			students:[],
			pageNum:0,
			currentPage:0,
			active:""
		},
		mounted(){
			this.getFriends(1);
		},
		methods:{
			getFriends:function(page){
				axios.get("/coach/getStudents?page="+page)
				.then(
					res => {
						if(res.data.code==1){
							this.students = res.data.data.list;
							
							this.currentPage = res.data.data.nowPage;
							this.pageNum = res.data.data.totalPage;
						}else{
							layer.alert("服务器忙，请稍后再试");
						}
					}
				
				)
			},
			prePage:function(){
				if(this.currentPage>1){
					this.getUnread(this.currentPage-1);
				}
			},
		
			nextPage:function(){
				if(this.currentPage<this.pageNum){
					this.getUnread(this.currentPage+1);
				}
			},
			delArray:function(id,list){
				for(var i=0;i<list.length;i++){
					if(list[i].id==id){
						list.splice(i,1);
						break;
					}
				}
				
				return list;
			},
		
			detail:function(id){
				location.href="/lsw/student_view.html?id="+id;			
			}
		}
	})
</script>
</html>